var _grid = $('#jgTable'); 
gridWidth = $('.u_toolbar');

$(function(){

    _gridInit();

    $("li[data-opt='opt_search']").find(">i").on('click', function(){
        gridSearch.Content = {
            SearchText: $("#opt_search").find(">input").val()
        };
        search();
    });

    //$('.modal-data').draggable();

});

function alarmFormatter(cellvalue, options, rowdata){
    var grid = $(this);
    if(JSON.stringify(rowdata)!=='{}'){
        cellvalue = '<a href="javascript:0" opt-data="'+grid[0].id+'_edit" title="编辑"><i class="fa fa-pencil"></i></a>'+
            '&nbsp;<a href="javascript:0" opt-data="'+grid[0].id+'_delete" title="删除"><i class="fa fa-trash-o"></i></a>';
    }else{
        cellvalue = '';
    }
    return cellvalue;
}
function _gridInit(){
    var _gridData = Object.create(gridData);
    _gridData.url = omsPath + '/OMS0001/OMS000102';
    _gridData.colModel = [
        {label:'订单号', name:'OrderNo'},
        {label:'单据状态', name:'DocStatus'},
        {label:'用户代码', name:'UserCode'},
        {label:'用户名称', name:'UserName'},
        {label:'单据总计', name:'DocTotal'},
        {label:'单据状态', name:'DocStatus'},
        {label:'公司代码', name:'CardCode'},
        {label:'公司名称', name:'CardName'},
        {label:'开票公司名称', name:'TaxCompany'},
        {label:'开票类型', name:'TaxType'},
        {label:'开票开户行', name:'TaxBank'},
        {label:'开票账号', name:'TaxAccount'},
        {label:'开票税号', name:'TaxNumber'},
        {label:'开票地址', name:'TaxAddress'},
        {label:'开票电话', name:'TaxPhone'},
        {label:'计划发货日期', name:'DeliverDate'},
        {label:'收货地址ID', name:'AddressId'},
        {label:'省', name:'Province'},
        {label:'地区', name:'Area'},
        {label:'市', name:'City'},
        {label:'街道', name:'Street'},
        {label:'收货详细地址', name:'Address'},
        {label:'收货人', name:'Receiver'},
        {label:'收货人电话', name:'ReceiverPhone'},
    ];
    _gridData.sortname = 'OrderNo';
    var _postData = {
        Content:{
            SearchText: ''
        }
    };
    for(i in postData){
        _postData[i] = postData[i];
    }
    //console.log(postData)
    _gridData.beforeRequest = function(){
        _gridData.grid.jqGrid("setGridParam", {
            postData : _postData,
        });
    };
    _gridData.loadComplete = function(xhr){
        $('a[opt-data="jgTable_edit"]').unbind('click').bind('click', function(){
            var rowId = $(this).parent().parent()[0].id;
            editCode(rowId);
        });
        $('a[opt-data="jgTable_delete"]').unbind('click').bind('click', function(){
            var rowId = $(this).parent().parent()[0].id;
            deleteCode(rowId);
        });
    };
    gridInit(_gridData);
    gridSearch = _postData;
}